<template>
    <div class="app-container">
        <!-- 表格-条件筛区域  -->
        <div class="filter-container">
            <el-input placeholder="请输入内容" v-model="searchParam.SEARCH_LIKE_content" style="width: 200px;"
                      class="filter-item" @keyup.enter.native="handleFilter"/>
            <el-input placeholder="请输入类型" v-model="searchParam.SEARCH_LIKE_reportTypeName" style="width: 200px;"
                      class="filter-item" @keyup.enter.native="handleFilter"/>
            <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"> 搜索</el-button>
            <el-button class="filter-item" type="default" icon="el-icon-search" @click="searchReset"> 重置</el-button>
            </el-button>
        </div>

        <!-- 表格-内容区域 -->
        <el-table v-loading="listLoading" :key="tableKey" :data="tableList" border fit highlight-current-row
                  style="width: 100%;">
            <el-table-column v-for="column in columns" :key="column.prop"
                             :prop="column.prop"
                             :label="column.label"
                             :width="column.width"
                             :align="column.align?column.align:'center'"
                             :min-width="column.minWidth"
                             :sortable="column.sortable"
                             :fixed="column.fixed"
                             :type="column.type" :formatter="column.formatter">
                <template slot-scope="scope">
                    <!-- 行内显示图片 -->
                    <img v-if="column.imgFlag==true"
                         :src=" scope.row[column.prop].indexOf('http://') >-1 ?  scope.row[column.prop] : ( CMBASE.baseFileContext + scope.row[column.prop] ) "
                         width="60" height="60" class="img" alt=""/>
                    <!-- 行内显示开关按钮 -->
                    <el-switch v-else-if="column.switchFlag==true" v-model="scope.row[column.prop]" :active-value="1"
                               :inactive-value="0" disabled></el-switch>
                    <!-- 行内显示tag标签 -->
                    <span v-else-if="column.tagFlag==true">
                        <span v-for="item in column.tagFormatter" :key="item.value">
                            <el-tag v-if="item.value==scope.row[column.prop]" :type="item.type">{{ item.text }}</el-tag>
                        </span>
                    </span>
                    <!-- 行内格式自定义 -->
                    <span v-else-if="column.formatter"> {{ column.formatter(scope.row) }}</span>
                    <!--默认显示文本-->
                    <span v-else>{{ scope.row[column.prop] }}</span>
                </template>
            </el-table-column>

            <el-table-column label="操作" align="center" width="240" class-name="small-padding">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="handleUpdate(scope.row)"> 查看</el-button>
                    <el-button type="danger" size="mini" @click="handleDelete(scope.row)"> 删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 表格-页脚区域 -->
        <pagination v-show="tableTotal>0" :total="tableTotal" :page.sync="pageRequest.pageNum"
                    :limit.sync="pageRequest.pageSize" @pagination="getList"/>
        <el-dialog :title="'查看'" width="45%" top="5vh" :visible.sync="dialogFormVisible"
                   :close-on-click-modal="false">
            <el-form :model="dataForm" label-width="140px"  ref="dataForm" style="width: 95%" disabled>
                <el-form-item label="举报内容" prop="content">
                    <el-input v-model="dataForm.content" auto-complete="off" placeholder="请输入举报内容"/>
                </el-form-item>
                <el-form-item label="举报用户" prop="userName">
                    <el-input v-model="dataForm.userName" auto-complete="off" placeholder="请输入举报用户"/>
                </el-form-item>
                <el-form-item label="举报直播间" prop="title">
                    <el-input v-model="dataForm.title" auto-complete="off" placeholder="请输入举报直播间"/>
                </el-form-item>
                <el-form-item label="举报类型" prop="reportTypeName">
                    <el-input v-model="dataForm.reportTypeName" auto-complete="off" placeholder="请输入举报类型"/>
                </el-form-item>
                <el-form-item  label="举报图片" prop="reportImage">
                    <cm-upload-more v-if="dataForm.reportImage" v-model="dataForm.reportImage"  :value="dataForm.reportImage" :limit="4" ></cm-upload-more>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click.native="closeDialog()">取消</el-button>
                </el-button>
            </div>
        </el-dialog>

    </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 分页栏信息
// import CmUpload from '@/components/Upload' // 上传图片组件引入
import CmUploadMore from '@/components/UploadMore' // 上传图片组件引入
import {
    getViewLiveReportList,
    deleteJdLiveReport,
} from '@/api/modules/live'

export default {
    name: 'liveReport',
    components: {
        Pagination,
        // CmUpload,
        CmUploadMore
    },
    directives: {},
    filters: {},
    data() {
        return {
            tableKey: 0,
            tableList: [],//表格数据源
            tableTotal: 0,//表格总条数数据
            listLoading: true,
            pageRequest: {pageNum: 1, pageSize: 10,},
            searchParam: {},
            dialogFormVisible: false,//默认不显示弹出框
            operation: true, // true:新增, false:编辑
            editLoading: false,//保存表单时loading框
            columns: [
                {prop: 'content', label: '举报内容', sortable: false},
                {prop: 'userName', label: '举报用户', sortable: false},
                {prop: 'ct', label: '举报时间', sortable: false},
                {prop: 'title', label: '举报直播间', sortable: false},
                {prop: 'reportTypeName', label: '举报类型', sortable: false},
            ],
            fileList: [],
            // 新增编辑界面数据
            dataForm: {},
            //分类子项目
            typeId: '',
            formatTypeName: '分类子项目',
            getFormatTypeVisible: false, // 属性值列表页 隐藏
            operationFormat: true, // true:新增, false:编辑
            pageRequestFormat: {pageNum: 1, pageSize: 10},
            dialogFormVisibleFormat: false, // 默认不显示弹出框
            listLoadingFormat: true,
            tableListFormat: [], // 表格数据源
            tableTotalFormat: 0,
            editLoadingFormat: false,//保存表单时loading框
            // 新增编辑界面数据
            dataFormFormat: {},
        }
    },
    methods: {
        //获取表格数据
        getList() {
            this.listLoading = true
            //【API请求】----获取表格列表数据
            getViewLiveReportList(this.pageRequest).then(response => {
                response = response.result
                this.tableList = response.list
                this.tableTotal = response.total
                this.listLoading = false;
            }).catch((res) => {
                this.$message({message: res.msg, type: 'error'})
            })
        },
        //【按钮点击】--- 弹出编辑表单
        handleUpdate(row) {
            this.operation = false;
            this.dataForm = Object.assign({}, row)
            console.log("图片",this.dataForm.reportImage)
            //显示编辑菜单
            this.dialogFormVisible = true
            this.$nextTick(() => {
                this.$refs['dataForm'].clearValidate()
                this.editLoading = false;
            })
        },
        //表格数据筛选
        handleFilter() {
            this.pageRequest.searchParam = this.searchParam
            this.getList()
        },

        //【按钮点击】---删除行
        handleDelete(row) {
            this.$confirm('确认删除该记录吗？', '提示', {}).then(() => {
                //【API请求】---- 删除数据
                deleteJdLiveReport(row.id).then(() => {
                    this.$message({message: '操作成功', type: 'success'})
                    this.getList();
                })
            }).catch(() => {
                this.$message({message: '操作失败', type: 'error'})
            });
        },
        //初始化表单数据，重新渲染
        initDataForm() {
            this.dataForm = {
                id: '',
                name: '',
            };
        },
        // 重置按钮
        searchReset() {
            this.searchParam = {}
            this.pageRequest = {pageNum: 1, pageSize: 10}
            this.getList()
            this.typeId = ''
        },
        //关闭表单弹出框
        closeDialog() {
            this.$refs['dataForm'].resetFields();
            // this.$refs['dataForm'].clearFiles();
            this.dialogFormVisible = false
        },
    },
    created() {
        this.getList();
    },
}
</script>
